package com.achievement.project.system.scoreForStu.controller;

import java.util.List;

import com.achievement.common.utils.security.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.achievement.framework.aspectj.lang.annotation.Log;
import com.achievement.framework.aspectj.lang.enums.BusinessType;
import com.achievement.project.system.scoreForStu.domain.scoreForStu;
import com.achievement.project.system.scoreForStu.service.IscoreForStuService;
import com.achievement.framework.web.controller.BaseController;
import com.achievement.framework.web.domain.AjaxResult;
import com.achievement.common.utils.poi.ExcelUtil;
import com.achievement.framework.web.page.TableDataInfo;

/**
 * 班级成绩Controller
 *
 * @author zkai
 * @date 2021-05-04
 */
@Controller
@RequestMapping("/system/scoreForStu")
public class scoreForStuController extends BaseController
{
    private String prefix = "system/scoreForStu";

    @Autowired
    private IscoreForStuService scoreForStuService;

    @RequiresPermissions("system:scoreForStu:view")
    @GetMapping()
    public String scoreForStu()
    {
        return prefix + "/scoreForStu";
    }

    /**
     * 查询班级成绩列表
     */
    @RequiresPermissions("system:scoreForStu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(scoreForStu scoreForStu)
    {
        startPage();
        Long userId = ShiroUtils.getUserId();
        scoreForStu.setStudentId(userId);
        List<scoreForStu> list = scoreForStuService.selectscoreForStuList(scoreForStu);
        return getDataTable(list);
    }

    /**
     * 导出班级成绩列表
     */
    @RequiresPermissions("system:scoreForStu:export")
    @Log(title = "班级成绩", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(scoreForStu scoreForStu)
    {
        List<scoreForStu> list = scoreForStuService.selectscoreForStuList(scoreForStu);
        ExcelUtil<scoreForStu> util = new ExcelUtil<scoreForStu>(scoreForStu.class);
        return util.exportExcel(list, "班级成绩数据");
    }

    /**
     * 新增班级成绩
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存班级成绩
     */
    @RequiresPermissions("system:scoreForStu:add")
    @Log(title = "班级成绩", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(scoreForStu scoreForStu)
    {
        return toAjax(scoreForStuService.insertscoreForStu(scoreForStu));
    }

    /**
     * 修改班级成绩
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        scoreForStu scoreForStu = scoreForStuService.selectscoreForStuById(id);
        mmap.put("scoreForStu", scoreForStu);
        return prefix + "/edit";
    }

    /**
     * 修改保存班级成绩
     */
    @RequiresPermissions("system:scoreForStu:edit")
    @Log(title = "班级成绩", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(scoreForStu scoreForStu)
    {
        return toAjax(scoreForStuService.updatescoreForStu(scoreForStu));
    }

    /**
     * 删除班级成绩
     */
    @RequiresPermissions("system:scoreForStu:remove")
    @Log(title = "班级成绩", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(scoreForStuService.deletescoreForStuByIds(ids));
    }
}
